#include <stdio.h>
#include <math.h>

int base(int off) {
    int result = 1;
    for (int i = 0; i < off; i++) {
        result *= 10;
    }
    return result;
}

int move(int a, int b, int offset) {
    if (offset > 0) {
        return a * base(offset) + b;
    } else if (offset < 0) {
        return a + b * base(-offset);
    } else {
        return a + b;
    }
}

int main(void) {
    int n = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int a, b, c;
        scanf("%d+%d=%d", &a, &b, &c);
        if (a + b == c) {
            printf("0\n");
        }
        for (int off = 1; off < 8; off++) {
            if (move(a, b, off) == c) {
                printf("%d\n", off);
                break;
            }
        }
        for (int off = -1; off > -8; off--) {
            if (move(a, b, off) == c) {
                printf("%d\n", off);
                break;
            }
        }
    }
    return 0;
}
